﻿@model RBAC.Web.Models.UserModel
@using RBAC.Web.CustomHelpers
@using RBAC.Web.Mapper
@using RBAC.Web.Utilities
@{
    ViewBag.Title = "Add User";
    Layout = "~/Views/Shared/_Layout.cshtml";

    string returnUrl = Url.Action("ListUser", "User");
}

@section Styles {
    <script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/form.js")" type="text/javascript"></script>
    <link href="@Url.Content("~/Content/themes/base/jquery-ui.css")" rel="stylesheet" type="text/css" />
    <link href="@Url.Content("~/Content/themes/base/jquery.ui.datepicker.css")" rel="stylesheet" type="text/css" />

    <script type="text/javascript">
        $(function () {
            //How to setup Datepicker
            // SetDatePicker has 4 argurement
            // controlId -> id of control
            // maxdate -> maximun Date that can be selected 
            // mindate -> minimum Date that can be selected 
            // yearrange - > range of year
            // more information see http://api.jqueryui.com/datepicker/
            SetDatePicker("CreateDate", new Date(), '-71Y', 'c-70:c');
            //ถ้าไม่มีกำหนด maxdate, mindate, yearrange
            SetDatePicker("FreeDate");			 

            //How to setup Lookup
            // SetLookupFor has 3 argurement
            // controlId -> id of control
            // getLookupId -> hidden control's id for getlookup link
            // popLookupId -> hidden control's id for poplookup link
            SetExternalLookupFor("User_Role", "User_RoleGetExternalLookup", 
"User_RolePopExternalLookup", 'User_Role|User_RoleLookupField|RoleId');
			
        });
    </script>
}

<h2>New User</h2>


@using (Html.BeginForm("AddUser", "User", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
    @Html.ValidationSummary(false)
    <fieldset>
        <legend>UserModel</legend>


        <div class="two-column-container">


            <div class="texteditor">
                @Html.LabelFor(model => model.Username)
                @Html.EditorFor(model => model.Username)
                <input type="hidden" name="Mode" value="Add" />
            </div>


            <div class="texteditor">
                @Html.LabelFor(model => model.Password)
                @Html.EditorFor(model => model.Password)
            </div>




            <div class="texteditor">
                @Html.LabelFor(model => model.Email)
                @Html.EditorFor(model => model.Email)
            </div>


            <div class="texteditor">
                @Html.LabelFor(model => model.Mobile)
                @Html.EditorFor(model => model.Mobile)
            </div>

            <div class="texteditor">
                @Html.LabelFor(model => model.CreateDate)
                @Html.DatePickerFor(model => model.CreateDate, "CreateDate",true)

            </div>

            @* START ถ้าไม่มี lookup ไปหาแม่ ClildClass=False, LinkToParent=False *@
          
           @* chayawooth**********************************
             <div class="texteditor">
                @Html.LabelFor(model => model.RoleId)
                @Html.TextBoxFor(model => model.RoleId, new { @readonly = "readonly", @class = "txtFillNameExternal" })
            </div>
           *@


            <div class="texteditor">
                @Html.LabelFor(model => model.Role)
                @Html.ExternalLookup(model => model.RoleRoleCode, "User_Role").For(model => model.Role).Render()
            </div>
            @* END ถ้าไม่มี lookup ไปหาแม่ ClildClass=False, LinkToParent=False *@





            <div class="texteditor">
                @Html.LabelFor(model => model.UserStatus)
                @Html.RadioButtonForSelectList(model => model.UserStatus, UserStatusMapper.GetUserStatusSelectList())
            </div>


        </div>
        <div class="bottom-menu clear">
            <input type="submit" value="Add" />
            <input id="cancel" onclick="location.href='@returnUrl    '" type="button" value="Cancel" />
        </div>
    </fieldset>
}
